package com.onairm.baselibrary.net;

import android.util.Log;

import com.onairm.baselibrary.utils.TipToast;
import com.onairm.baselibrary.utils.Utils;


import rx.Subscriber;

/**
 * Created by apple on 17/11/2.
 */

public abstract class HttpResultSubscriber<T> extends Subscriber<BaseData<T>> {
    @Override
    public void onCompleted() {

    }

    @Override
    public void onStart() {
        super.onStart();
        if (!Utils.isNetAvailable()) {
            TipToast.longTip("连接失败");
        }
    }

    @Override
    public void onError(Throwable e) {
        onHttpError(e);
    }

    @Override
    public void onNext(BaseData<T> tBaseData) {
        if (tBaseData.getStatusCode() == 0) {
            onSuccess(tBaseData);
        }else if(tBaseData.getStatusCode()==2002){
            //TipToast.shortTip("账号过期");
        }else {
            onHttpError(new Throwable(tBaseData.getMessage()));
        }
    }


    public abstract void onSuccess(BaseData<T> t);

    public abstract void onHttpError(Throwable throwable);

}
